package com.WaVel.RabbitMqComponent;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class FanoutConfig {

    /**
     * 声明交换机
     * @return Fanout类型交换机
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("itcast.direct");
    }

    /**
     * 第1个队列:用于公司信息添加的队列
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 用于公司信息修改的队列
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 用于公司信息删除的队列
     */
    @Bean
    public Queue fanoutQueue3(){
        return new Queue("fanout.queue3");
    }

    /**
     * 绑定队列和交换机、添加公司信息后
     */
    @Bean
    public Binding bindingQueue1(Queue fanoutQueue1, DirectExchange directExchange){
        return BindingBuilder.bind(fanoutQueue1)
                .to(directExchange)
                .with("company.add");

    }

    /**
     * 绑定队列和交换机、修改公司信息
     */
    @Bean
    public Binding bindingQueue2(Queue fanoutQueue2, DirectExchange directExchange){
        return BindingBuilder.bind(fanoutQueue2)
                .to(directExchange)
                .with("company.update");

    }

    /**
     * 绑定队列和交换机、删除公司信息
     */
    @Bean
    public Binding bindingQueue3(Queue fanoutQueue3, DirectExchange directExchange){
        return BindingBuilder.bind(fanoutQueue3)
                .to(directExchange)
                .with("company.delete");

    }



    /**
     * 第2个交换机
     */
    @Bean
    public DirectExchange interviewExchange(){
        return new DirectExchange("interview_exchange");
    }

    /**
     * 第1个队列：面试问题添加执行
     */
    @Bean
    public Queue fanoutQueue4(){
        return new Queue("interview.add.queue");
    }

    /**
     * 第2个队列：面试问题修改执行
     */
    @Bean
    public Queue fanoutQueue5(){
        return new Queue("interview.update.queue");
    }

    /**
     * 第3个队列：面试问题删除执行
     */
    @Bean
    public Queue fanoutQueue6(){
        return new Queue("interview.delete.queue");
    }

    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding bindingQueue4(Queue fanoutQueue4, DirectExchange interviewExchange){
        return BindingBuilder.bind(fanoutQueue4)
                .to(interviewExchange)
                .with("interview.add");
    }

    @Bean
    public Binding bindingQueue5(Queue fanoutQueue5, DirectExchange interviewExchange){
        return BindingBuilder.bind(fanoutQueue5)
                .to(interviewExchange)
                .with("interview.update");
    }

    @Bean
    public Binding bindingQueue6(Queue fanoutQueue6, DirectExchange interviewExchange){
        return BindingBuilder.bind(fanoutQueue6)
                .to(interviewExchange)
                .with("interview.delete");
    }

}
